package com.superwein.alibaba.dubbo.consumer.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class DegradeExceptionHandleService {

    /**
     * 熔断与降级处理
     *
     * @param str
     */
    @SentinelResource(value = "doSomeThing2", fallback = "fallbackHandler")
    public String doSomeThing(String str) {
        log.info(str);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return str;
    }

    public String fallbackHandler(String str) {
        log.error("fallbackHandler：" + str);
        return "fallbackHandler：" + str;
    }

}
